<%--
  Created by IntelliJ IDEA.
  User: LANCHUNQIAN
  Date: 2016/11/21
  Time: 18:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>set</title>
    <meta http-equiv="Content-Type" content="text/html charset=gb2312">
    <script  type="text/javascript" src = "jquery-1.11.2.js"></script>
    <script>
        $(document).ready(function() {
            $("#set").click(function(){

                var upper = $("#upperLimit").val();
                var lower = $("#lowerLimit").val();
                var dir = $("#director").val();
                $("#content").append(
                        "<tr>" +
                        "<td><input type='text' value ='"+ lower + "' ></td>" +
                        "<td><input type='text' value = '"+ upper + "' ></td>" +
                        "<td><input type='text' value = '"+ dir + "'ir></td>" +
                        "</tr>");
                $("#upperLimit").val("");
                $("#lowerLimit").val("");
                $("#director").val("");
            });
        });

        function sub() {
            var result=[];
            $("#content").find("tr").each(function (index,tr) {
                result.push({
                    lowerLimit:$(tr).find("input").eq(0).val(),
                    upperLimit:$(tr).find("input").eq(1).val(),
                    director:$(tr).find("input").eq(2).val()
                })
            });
            alert(JSON.stringify(result));

            $.ajax({
                type:"POST",
                dataType: "json",
                url:"/setDirector/rule",
                data:{'orderRangeJson':JSON.stringify(result)},
                error:function(){alert("fail");},
                success:function(){
                    alert("success");
                }
            });
        }

        function get(){
            var orderPrice = $("#orderPrice").val();
            $.ajax({
                type:"POST",
                dataType: "json",
                url:"/setDirector/test",
                data:{'orderPrice' : orderPrice},
                error:function(){alert("fail");},
                success:function(data){
                    $("#orderDirector").val(data)
                }
            });
        }
    </script>

</head>
<body>
        <table>
            <tr>
                <td><input type = "text" id = "lowerLimit" name = "lowerLimit"/></td>
                <td><input type = "text" id = "upperLimit" name = "upperLimit"/></td>
                <td><input type = "text" id = "director" name = "director"/></td>
            </tr>
            <tr>
                <td><input id = "set" type = "button" value = "ok"/></td>
            </tr>
        </table>
        <table id = "content"></table>
        <input type = "button" value = "submit" onclick="sub();"/>

        <br/><br/><br/><br/>

        <table>
            <tr>
                <td><input id = "orderPrice" type = "text" name = "orderPrice"></td>
                <td><input id = "orderDirector" type = "test" name = "orderDirector"></td>
            </tr>
            <tr>
                <td><input id = "get" type = "button" value = "ok" onclick="get()"/></td>
            </tr>
        </table>
</body>
</html>
